package com.ruoyi.web.controller.combat.useralignment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.combat.domain.useralignment.CombatUserWb;
import com.ruoyi.combat.service.useralignment.ICombatUserWbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课题五微博用户信息Controller
 *
 * @author ruoyi
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/combat/userWb")
public class CombatUserWbController extends BaseController {
    @Autowired
    private ICombatUserWbService combatUserWbService;

    /**
     * 查询课题五微博用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatUserWb combatUserWb) {
        startPage();
        List<CombatUserWb> list = combatUserWbService.selectCombatUserWbList(combatUserWb);
        return getDataTable(list);
    }

    /**
     * 导出课题五微博用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:export')")
    @Log(title = "课题五微博用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatUserWb combatUserWb) {
        List<CombatUserWb> list = combatUserWbService.selectCombatUserWbList(combatUserWb);
        ExcelUtil<CombatUserWb> util = new ExcelUtil<CombatUserWb>(CombatUserWb.class);
        util.exportExcel(response, list, "课题五微博用户信息数据");
    }

    /**
     * 获取课题五微博用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatUserWbService.selectCombatUserWbById(id));
    }

    /**
     * 新增课题五微博用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:add')")
    @Log(title = "课题五微博用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatUserWb combatUserWb) {
        return toAjax(combatUserWbService.insertCombatUserWb(combatUserWb));
    }

    /**
     * 修改课题五微博用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:edit')")
    @Log(title = "课题五微博用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatUserWb combatUserWb) {
        return toAjax(combatUserWbService.updateCombatUserWb(combatUserWb));
    }

    /**
     * 删除课题五微博用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userWb:remove')")
    @Log(title = "课题五微博用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatUserWbService.deleteCombatUserWbByIds(ids));
    }
    @ApiOperation("采集数据数据")
    @Anonymous
    @PostMapping("/crawlData")
    public AjaxResult crawLData(@RequestBody List<String> ids) {
        return toAjax(combatUserWbService.crawLData(ids));
    }

    @ApiOperation(value = "按照用户id采集用户信息及发布内容")
    @GetMapping("/weibo")
    public AjaxResult crawlWeiboByUserId(@ApiParam(name = "id", value = "需要采集的用户id", required = true)
                                         @RequestParam(required = true) String id) {
        combatUserWbService.crawlWeiboByUserId(id);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }
}
